package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250124092739CreateRolePermissionsTable struct {
}

// Signature The unique signature for the migration.
func (r *M20250124092739CreateRolePermissionsTable) Signature() string {
	return "20250124092739_create_role_permissions_table"
}

// Up Run the migrations.
func (r *M20250124092739CreateRolePermissionsTable) Up() error {
	if !facades.Schema().HasTable("role_permissions") {
		return facades.Schema().Create("role_permissions", func(table schema.Blueprint) {
			table.ID()
			//table.Integer("tenant_id").Nullable().Default(0).Unsigned().Comment("租户id")
			table.Integer("role_id").Unsigned().Comment("角色id")
			table.Integer("permission_id").Unsigned().Comment("权限id")
			table.Timestamps()

			table.Unique("role_id", "permission_id")
		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20250124092739CreateRolePermissionsTable) Down() error {
	return facades.Schema().DropIfExists("role_permissions")
}
